package com.yunhe.abnormal.consts;

import com.yunhe.common.constant.CacheConsts;
import com.yunhe.common.constant.LanguageConsts;
import com.yunhe.common.util.StringUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 告警状态Key常量类
 * @author liuronglei
 */
public class AbnormalStatusKey {
    /**
     * 通用key定义
     */
    private static String getKey(Long id,
                                 String name,
                                 Long code,
                                 String language) {
        List<String> keyList = new ArrayList<>();
        if (id != null) {
            keyList.add("id" + CacheConsts.SPLIT_FIELD + id);
        }
        if (!StringUtil.isEmpty(name)) {
            keyList.add("n" + CacheConsts.SPLIT_FIELD + name);
        }
        if (code != null) {
            keyList.add("c" + CacheConsts.SPLIT_FIELD + code);
        }
        if (language != null) {
            keyList.add("lan" + CacheConsts.SPLIT_FIELD + language);
        } else {
            keyList.add("lan" + CacheConsts.SPLIT_FIELD + LanguageConsts.TYPE.ZH.value());
        }
        return StringUtils.join(keyList.toArray(), CacheConsts.SPLIT_TYPE);
    }

    public static String getIdKey(Long id, String language) {
        return getKey(id ,null, null, language);
    }

    public static String getNameKey(String name, String language) {
        return getKey(null ,name, null, language);
    }

    public static String getCodeKey(Long code, String language) {
        return getKey(null ,null, code, language);
    }

    public static String getAllKey(String language) {
        return "All" + CacheConsts.SPLIT_FIELD + language;
    }
}
